import java.util.*;

public class Homework {
    static public Scanner sc = new Scanner(System.in);

    // 公鸡5元一只，母鸡3元一只，小鸡1元三只，现在打算用100元买一百只鸡，列出所有可能的组合
    static public void buy() {
        int i, j, k;

        /*
         * for (i = 0; i < 21; ++i) {
         *     for (j = 0; j < 34; ++j) {
         *         for (k = 0; k < 101; ++k) {
         *             if (k % 3 == 0 && i + j + k == 100
         *                         && i * 5 + j * 3 + k / 3 == 100) {
         *                 System.out.printf("公鸡: %d, 母鸡: %d, 小鸡: %d\n",
         *                         i, j, k);
         *             }
         *         }
         *     }
         * }
         */
        for (i = 0; i < 21; ++i) {
            for (j = 0; j < 34; ++j) {
                k = 100 - i - j;
                if (k % 3 == 0 && i * 5 + j * 3 + k / 3 == 100) {
                    System.out.printf("公鸡: %d, 母鸡: %d, 小鸡: %d\n",
                            i, j, k);
                }
            }
        }
    }

    // 已知1900年的一月一号是星期一，问今年有多少个黑色星期五，(每个月的13号是星期五即黑色星期五)
    static public void blackFri() {
        int startYear = 1900;
        int nowYear = 2017;
        int days = 0, i;

        System.out.printf("请输入计算年: ");
        nowYear = sc.nextInt();

        while (startYear < nowYear) {
            days += 365;
            if (startYear % 4 == 0 && startYear % 100 != 0
                        || startYear % 400 == 0) {
                days += 1;
            }
            ++startYear;
        }
        days += 13;

        for (i = 1; i < 13; ++i) {
            switch (i) {
                case 2:
                case 4:
                case 6:
                case 8:
                case 9:
                case 11:
                    days += 31;
                    break;
                case 3:
                    if (nowYear % 4 == 0 && nowYear % 100 != 0 || nowYear % 400 == 0) {
                        days += 29;
                    } else {
                        days += 28;
                    }
                    break;
                case 5:
                case 7:
                case 10:
                case 12:
                    days += 30;
                    break;
                case 1:
                default:
                    break;
            }
            if (days % 7 == 5) {
                System.out.printf("%d 年 %d 月 13号 是黑色星期五!\n", nowYear, i);
            }
        }
    }

    // 某人从2000年1月1号开始过着三天打鱼两天晒网的生活，输入年月日，查询那一天此人是在打鱼还是在晒网
    static public void fish() {
        int startYear = 2000;
        int year = startYear, month = 1, day = 1;
        int days = 0, i;

        while (true) {
            System.out.printf("请输入年(-1为返回主菜单): ");
            year = sc.nextInt();
            System.out.printf("请输入月(-1为返回主菜单): ");
            month = sc.nextInt();
            System.out.printf("请输入日(-1为返回主菜单): ");
            day = sc.nextInt();

            if (year == -1 || month == -1 || day == -1)
                break;

            days = day;
            while (startYear < year) {
                days += 365;
                if (startYear % 4 == 0 && startYear % 100 != 0
                            || startYear % 400 == 0) {
                    days += 1;
                }
                ++startYear;
            }

            for (i = 1; i <= month; ++i) {
                switch (i) {
                    case 2:
                    case 4:
                    case 6:
                    case 8:
                    case 9:
                    case 11:
                        days += 31;
                        break;
                    case 3:
                        if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                            days += 29;
                        } else {
                            days += 28;
                        }
                        break;
                    case 5:
                    case 7:
                    case 10:
                    case 12:
                        days += 30;
                        break;
                    case 1:
                    default:
                        break;
                }
            }

            days %= 5;
            if (days == 4 || days == 0) {
                System.out.println("此人在晒网!");
            } else {
                System.out.println("此人在打鱼!");
            }
        }
    }

    // 输入边长打印直角三角形用一个循环
    static public void triangle() {
        System.out.printf("请输入边长: ");
        int b = sc.nextInt();

        int i, j, s;
        for (i = 0; i < b; ++i) {
            for (j = 0; j <= i; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        for (i = 0; i < b; ++i) {
            for (j = 0, s = b - i; j < s; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        for (i = 0; i < b; ++i) {
            for (j = 0; j < i; ++j) {
                System.out.printf("   ");
            }
            for (j = 0, s = b - i; j < s; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        for (i = 0; i < b; ++i) {
            for (j = 0, s = b - i - 1; j < s; ++j) {
                System.out.printf("   ");
            }
            for (j = 0; j <= i; ++j) {
                System.out.printf(" * ");
            }
            System.out.println();
        }

        System.out.println();

        int r, c;
        for (i = 0, s = b * b; i < s; ++i) {
            r = i / b;
            c = i % b;

            if (c <= r)
                System.out.printf(" * ");
            else
                System.out.printf("   ");

            if (c + 1 == b)
                System.out.println();
        }

        for (i = 0, s = b * b; i < s; ++i) {
            r = i / b;
            c = i % b;

            if (c >= r)
                System.out.printf(" * ");
            else
                System.out.printf("   ");

            if (c + 1 == b)
                System.out.println();
        }

        for (i = 0, s = b * b; i < s; ++i) {
            r = i / b;
            c = i % b;

            if (c >= b - r - 1)
                System.out.printf(" * ");
            else
                System.out.printf("   ");

            if (c + 1 == b)
                System.out.println();
        }

        for (i = 0, s = b * b; i < s; ++i) {
            r = i / b;
            c = i % b;

            if (c <= b - r - 1)
                System.out.printf(" * ");
            else
                System.out.printf("   ");

            if (c + 1 == b)
                System.out.println();
        }
    }

    static public void main(String [] args) {
        int input;
        boolean quit = false;

        while (!quit) {
            System.out.println("==== 作业 ====");
            System.out.println("1. 买鸡!");
            System.out.println("2. 黑色星期五!");
            System.out.println("3. 打鱼晒网!");
            System.out.println("4. 直角三角形!");
            System.out.println("5. 退出");
            System.out.printf("请输入[1 - 5]: ");
            input = sc.nextInt();

            switch (input) {
                case 1:
                    buy();
                    break;
                case 2:
                    blackFri();
                    break;
                case 3:
                    fish();
                    break;
                case 4:
                    triangle();
                    break;
                case 5:
                    quit = true;
                    break;
                default:
                    break;
            }
        }
    }
}
